package com.itheima.controller;

import com.itheima.cloud.pojo.User;
import com.itheima.cloud.response.UserOrderVo;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
@RefreshScope
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    Environment environment;

    @Value("${test.name}")
    private String name;
    /**
     * 根据用户名查询用户信息
     * @param username
     * @return
     */
    @GetMapping("findUserById/{username}")
    public User findUserById(@PathVariable("username") String username){
        System.out.println("Server PORT: " +environment.getProperty("server.port"));
        System.out.println("name="+name);
        return userService.findUserById(username);
    }

    /**
     *根据用户名查询用户的订单
     * @param username
     * @return
     */
    @GetMapping("findOrderByUserName/{username}")
    public UserOrderVo findOrderByUserName(@PathVariable("username") String username){
        return userService.findOrderByUserName(username);
    }
}
